package ru.ksu.ktk.diploma.sdi.util;

import com.hp.hpl.jena.ontology.OntModel;
import com.hp.hpl.jena.util.FileUtils;

import java.io.IOException;
import java.io.File;
import java.io.FileWriter;

/**
 * @author NZhiltsov
 *         Time: 14:48:01
 */
public class FileUtil {
    private static final String SYS_DELIMITER_WINDOWS = "\\";
    private static final String SYS_DELIMITER_UNIX = "/";

    /**
     * return file name with extension (if exists) from full file name
     *
     * @param fullFileName
     * @return
     */
    public static String getFileName(String fullFileName) {
        if (fullFileName == null || fullFileName.length() == 0)
            throw new IllegalArgumentException("file name cannot be empty");

        String sysDelimiter;
        if (fullFileName.contains(SYS_DELIMITER_UNIX))
            sysDelimiter = SYS_DELIMITER_UNIX;
        else if (fullFileName.contains(SYS_DELIMITER_WINDOWS))
            sysDelimiter = SYS_DELIMITER_WINDOWS;
        else
            return fullFileName;

        int lastDelimiterIndex = fullFileName.lastIndexOf(sysDelimiter);
        if (lastDelimiterIndex > 0 && lastDelimiterIndex < fullFileName.length() - 1)
            return fullFileName.substring(lastDelimiterIndex + 1);
        throw new IllegalArgumentException("file name is incorrect:" + fullFileName);
    }

}
